package com.joysuch.wwyt.core.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joysuch.wwyt.core.bean.FileChunkItem;
import com.joysuch.wwyt.core.mapper.FileChunkItemMapper;
import com.joysuch.wwyt.core.service.FileChunkItemService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 描述：文件分片 实现
 *
 * @author zhangcancan
 * @date 2023/3/27 16:52
 **/
@Service
public class FileChunkItemServiceImpl extends ServiceImpl<FileChunkItemMapper,FileChunkItem> implements FileChunkItemService {


    @Override
    public List<FileChunkItem> listByFileIdAndMd5(String fileMd5, Long fileId) {

        return this.list(Wrappers.<FileChunkItem>lambdaQuery()
                .eq(FileChunkItem::getFileId, fileId)
                .eq(FileChunkItem::getFileMd5, fileMd5));

    }

    @Override
    public Boolean saveChunkItem(FileChunkItem item) {

        if (Objects.isNull(item)) {
            return false;
        }
        return this.save(item);
    }
}
